package com.youlian.cloud.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.RowMapperResultSetExtractor;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * 记录耗时
 *
 * @author : liukx
 * @create : 2018/9/19 17:17
 * @email : liukx@elab-plus.com
 */
public class TimeRowMapperResultSetExtractor<T> extends RowMapperResultSetExtractor<T> {

    private Logger logger = LoggerFactory.getLogger(TimeRowMapperResultSetExtractor.class);

    public TimeRowMapperResultSetExtractor(RowMapper<T> rowMapper) {
        super(rowMapper);
    }

    public TimeRowMapperResultSetExtractor(RowMapper<T> rowMapper, int rowsExpected) {
        super(rowMapper, rowsExpected);
    }

    @Override
    public List<T> extractData(ResultSet rs) throws SQLException {
        long start = System.currentTimeMillis();
        List<T> list = super.extractData(rs);
        long time = System.currentTimeMillis() - start;
        logger.info(" 反射耗时 : " + time);
        System.out.println(list.size() + " 反射耗时 : " + time);
        return list;
    }
}
